package com.elt.text;

import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.elt.screen.ScreenWH;

public class TextUtil {

	public static void changeViewSize(ViewGroup viewGroup, int screenWidth,
			int screenHeight) {
		float adjustFontSize = adjustFontSize();
		for (int i = 0; i < viewGroup.getChildCount(); i++) {
			View v = viewGroup.getChildAt(i);
			if (v instanceof ViewGroup) {
				changeViewSize((ViewGroup) v, screenWidth, screenHeight);
			} else if (v instanceof Button) {
				float textsize = ((Button) v).getTextSize();
				((Button) v).setTextSize(adjustFontSize * textsize + 2);
			} else if (v instanceof TextView) {
				float textsize = ((TextView) v).getTextSize();
				((TextView) v).setTextSize(adjustFontSize * textsize);
			}
		}
	}

	public static void changeViewSize(ViewGroup viewGroup) {
		float adjustFontSize = adjustFontSize();
		for (int i = 0; i < viewGroup.getChildCount(); i++) {
			View v = viewGroup.getChildAt(i);
			if (v instanceof ViewGroup) {
				changeViewSize((ViewGroup) v);
			} else if (v instanceof Button) {
				float textsize = ((Button) v).getTextSize();
				((Button) v).setTextSize(adjustFontSize * textsize + 2);
			} else if (v instanceof TextView) {
				float textsize = ((TextView) v).getTextSize();
				((TextView) v).setTextSize(adjustFontSize * textsize);
			}
		}
	}

	public static float adjustFontSize() {

		float rate = (float) (ScreenWH.SCREEN_SIZE / 4);

		if (ScreenWH.SCREEN_SIZE < 5 && ScreenWH.width > 700) {
			rate = (float) (ScreenWH.SCREEN_SIZE / 5);
		}

		if (ScreenWH.SCREEN_SIZE < 3.5) {
			rate = (float) (ScreenWH.SCREEN_SIZE / 2);
		}

		// s4
		if (ScreenWH.SCREEN_SIZE >= 4.5 && ScreenWH.width > 1070) {
			rate = (float) (ScreenWH.SCREEN_SIZE / 8);
		}
		return rate;
	}
}
